package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.NewsSign;
import cn.wolfcode.trip.base.mapper.NewsSignMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.INewsSignService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NewsSignServiceImpl implements INewsSignService {
    @Autowired
    private NewsSignMapper newsSignMapper;


    @Override
    public NewsSign get(Long id) {
        return newsSignMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<NewsSign> listAll() {
        return newsSignMapper.selectAll();
    }

    @Override
    public void save(NewsSign newsSign) {
        //设置点赞或者收藏的时间
        if (newsSign.getGreatStatus() != null) {
            newsSign.setGreatTime(new Date());
        }
        if (newsSign.getEnshrineStatus() != null) {
            newsSign.setEnshrineTime(new Date());
        }
        newsSignMapper.insert(newsSign);
    }

    @Override
    public void update(NewsSign newsSign) {
        //设置点赞或者收藏的时间
        if (newsSign.getGreatStatus() != null) {
            newsSign.setGreatTime(new Date());
        }
        if (newsSign.getEnshrineStatus() != null) {
            newsSign.setEnshrineTime(new Date());
        }
        newsSignMapper.updateByPrimaryKey(newsSign);

    }


    @Override
    public PageInfo queryForList(QueryObject qo) {
        return null;
    }

    @Override
    public void updateState(NewsSign newsSign) {

    }


    /**
     * 根据大攻略id查询当前用户的在该攻略下的标记状态
     *
     * @param newsId
     * @return
     */
    @Override
    public NewsSign selectByNewsId(Long newsId, Long userId) {

        return newsSignMapper.selectByNewsId(newsId, userId);
    }

    @Override
    public int queryGreatStatusCountByNewsId(Long newsId) {

        return newsSignMapper.queryGreatStatusCountByNewsId(newsId);
    }

    @Override
    public int queryEnshrineStatusCountByNewsId(Long newsId) {
        return newsSignMapper.queryEnshrineStatusCountByNewsId(newsId);
    }


}
